﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
using System.Configuration;

namespace SomethingSpacial.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        public string RenderedRSSHTML = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        { 
            System.Net.WebRequest myRequest = System.Net.WebRequest.Create(ConfigurationManager.AppSettings["DefaultNewsRSS"].ToString());
            System.Net.WebResponse myResponse = myRequest.GetResponse();

            System.IO.Stream rssStream = myResponse.GetResponseStream();
            System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();
            rssDoc.Load(rssStream);

            System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");

            string title = "";
            string link = "";
            string description = "";

            for (int i = 0; i < rssItems.Count; i++)
            {
                System.Xml.XmlNode rssDetail;

                rssDetail = rssItems.Item(i).SelectSingleNode("title");
                title = (rssDetail != null) ? rssDetail.InnerText : string.Empty;

                rssDetail = rssItems.Item(i).SelectSingleNode("link");
                link = (rssDetail != null) ? rssDetail.InnerText : string.Empty;

                rssDetail = rssItems.Item(i).SelectSingleNode("description");
                description = (rssDetail != null) ? rssDetail.InnerText : string.Empty;

                RenderedRSSHTML += "<p><b><a href='" + link + "' target='new'>" + title + "</a></b><br/>" + description + "</p>";
            }
        }
    }
}
